// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext: Repair vehicle for engineer
// -----------------------------------------------

private ["_object","_list","_name","_text"];

_list = nearestObjects [getPosATL player, ["LandVehicle", "Air", "Tank", "Car"], 8];

if (count _list == 0) exitWith {
	wcgarbage = [localize "STR_WC_MENUREPAIRVEHICLE2", localize "STR_WC_MESSAGENOVEHICLENEARYOU", localize "STR_WC_MESSAGEGOCLOSERREPAIR", 3] spawn WC_fnc_playerhint;
};

player playMove "AinvPknlMstpSlayWrflDnon_medic";

_object = _list select 0;

if (getDammage _object > 0.90) then {
	wcgarbage = [localize "STR_WC_MENUREPAIRVEHICLE2", localize "STR_WC_MESSAGECANNOTREPAIR", "", 3] spawn WC_fnc_playerhint;
} else {
	_name = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "DisplayName");
	wcgarbage = [format [localize "STR_WC_MENUREPAIRVEHICLE2", _name], "You are repairing vehicle", "", 6] spawn WC_fnc_playerhint;
	sleep 6;
	if !(alive player) exitWith {};
	_object setDamage (getDammage _object - 0.1);
	_text = format ["Still %1 of dammage.", format ["%1", ceil ((getDammage _object) * 100)] + "%"];
	wcgarbage = [format [localize "STR_WC_MENUREPAIRVEHICLE2", _name], _text, "", 3] spawn WC_fnc_playerhint;
};